package com.ldkj.msg.com.liaodu.utils;

import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * Created by wuyukang on 2020/1/9.
 */
public class StringUtil {

    public static void main(String[] args) {
        MultiValueMap<String, Object> postData = new LinkedMultiValueMap<String, Object>();
        postData.add("username", "中单");
        postData.add("nickname", "李四");
        sendPost4(postData,"http://192.168.0.110:8088/rtsp/rcontact");
    }

    public static void sendPost4(MultiValueMap<String, Object> postData,String url){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());

        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(postData);
        HttpEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
        System.out.println("headers: " + response.getHeaders());
        System.out.println("body: " + response.getBody());
    }

}
